#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);

	if (!_server.listen()) {
		QMessageBox::critical(this, tr("Threaded Fortune Server"),
							  tr("Unable to start the server: %1.")
							  .arg(_server.errorString()));
		close();
		return;
	}

	ui->portEdit->setText(QString().setNum(_server.serverPort()));

	_logger = new Logger(ui->textEdit, this);
	_server.setLogger(_logger);
}

MainWindow::~MainWindow()
{
	_server.close();
	delete ui;
}
